<!--
	作者：offline
	时间：2018-09-03
	描述：送货单列表
-->
<template>
	<div class="m-view-deliveryList m-window">
		<div class="m-condition" v-if="diaShow">
			<el-row :gutter="10">
				<el-form
					:model="ruleForm"
					ref="ruleForm"
					label-width="70px"
					:inline-message="true"
					label-position="left"
				>
					<el-col :span="6">
						<el-form-item :label="accountType==1?'公司':'客户'" class="rightItem">
							<el-select
								value-key="id"
								v-model="companyCode"
								@change="companyChange"
								ref="content"
								:placeholder="`请选择${accountType==1?'公司':'客户'}`"
								filterable
								clearable
							>
								<el-option
									v-for="item in comOptions"
									:key="item.id"
									:label="item.companyName"
									:value="item.companyCode"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="创建时间" class="rightItem">
							<el-date-picker
								v-model="applySDate"
								type="date"
								:placeholder="placeholderS"
								:picker-options="pickerOptions"
								value-format="yyyy-MM-dd"
								:editable="false"
								:clearable="true"
							></el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-date-picker
							v-model="applyEDate"
							type="date"
							:placeholder="placeholderE"
							:picker-options="pickerEndOptions"
							value-format="yyyy-MM-dd"
							:editable="false"
							:clearable="false"
						></el-date-picker>
					</el-col>
					<el-col :span="6">
						<el-form-item label="单据状态" class="rightItem">
							<el-select
								value-key="id"
								v-model="billState"
								placeholder="请选择单据状态"
								@change="billStateChange"
								:disabled="btnDis"
							>
								<el-option
									v-for="item in billStateOptions"
									:key="item.id"
									:label="item.label"
									:value="item.value"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-form>
			</el-row>
			<el-row :gutter="10">
				<el-form
					:model="ruleForm"
					ref="ruleForm"
					label-width="70px"
					:inline-message="true"
					label-position="left"
				>
					<el-col :span="6" v-if="accountType==1">
						<el-form-item label="供应商" class="rightItem">
							<el-select
								filterable
								clearable
								v-model="supplierCode"
								placeholder="请选择供应商"
								@focus="focusMethod"
								@clear="supplierOptions=allSupplier"
								@change="supplierChange"
								:filter-method="filterSupplier"
							>
								<el-option
									v-for="item in supplierOptions"
									:key="item.id"
									:label="item.supplierName"
									:value="item.supplierCode"
								>
									<span style="float: left">{{ item.supplierName }}</span>
									<span style="float: right; color: #8492a6; font-size: 13px">{{ item.supplierCode }}</span>
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="采购单号" class="rightItem">
							<el-input v-model="purOrdNo" placeholder="请输入采购订单号" clearable></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="送货单号" class="rightItem">
							<el-input v-model="deliveryNo" placeholder="请输入送货单号" clearable></el-input>
						</el-form-item>
					</el-col>
				</el-form>
				<el-col :span="3" v-if="printDis && printJPDAuth" class="m-floatRight">
					<el-button type="primary" @click="printTemp('delivery')" v-if="printDis && printJPDAuth">拣配单打印</el-button>
				</el-col>
				<el-col :span="3" v-if="!printDis" class="m-floatRight">
					<el-button type="primary" @click="printTemp('sendDelivery')" v-if="!printDis">送货单打印</el-button>
				</el-col>
				<el-col :span="2" v-if="btnShow&&accountType!=1" class="m-floatRight">
					<el-button type="primary" @click="del">删除</el-button>
				</el-col>
				<el-col :span="2" class="m-floatRight">
					<el-button type="primary" @click="search(1)" :disabled="btnDis">查询</el-button>
				</el-col>
			</el-row>
		</div>
		<div class="m-agTable m-bottom m-top2" v-if="diaShow">
			<agGridComponents
				ref="agGridComponent"
				:getGridOptions="gridOptions"
				:getColumnDefs="columnDefs"
				:isColFit="true"
				:getRowSelection="rowSelection"
			></agGridComponents>
		</div>
		<div class="m-page" v-if="diaShow">
			<el-pagination
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				@prev-click="handlePrevClick"
				@next-click="handleNextClick"
				:current-page="currentPage"
				:page-sizes="[30,50,100,150,200]"
				:page-size="pageSize"
				layout="total, sizes, prev, pager, next, jumper"
				:total="total"
			></el-pagination>
		</div>

		<div class="m-window" v-if="componentShow">
			<deliveryComponents
				@cancelComponents="cancelComponents"
				@viewOrder="viewOrder"
				:getClickValue="getClickValue"
				:supplierInfo="supplierInfo"
				:pageLayOut="pageLayOut"
			></deliveryComponents>
		</div>
		<div class="m-window" v-if="orderShow">
			<purOrderDetailsComponents
				@cancelComponents="cancelComponents"
				:getClickValue="order"
				:ordStatus="ordStatus"
			></purOrderDetailsComponents>
		</div>
	</div>
</template>

<script>
import _Api from "@/api";
import { startPrint } from 'lesso-common/webprint'
import { mapState, mapMutations } from "vuex";
import agGridComponents from "@/components/agGridComponents.js"
import buttonLink from "@/components/buttonLink.js";
import deliveryComponents from "@/views/myLogistics/deliveryComponents";
import purOrderDetailsComponents from "@/views/purchase/purOrderDetailsComponents";
import supplierInfo from "@/public/supplierInfo.js";
import serviceTime from "@/public/serverTime.js";
import waterfall from "async-es/waterfall";
import fileStream from "@/public/fileStream.js";
import authInfo from "@/public/authInfo";
import constant from "@/public/constant";
import apienv from '@/api/env';
import aes from '@/public/aes';
import Msg from "@/public/message.js";


const ENV = apienv[constant.appenv]

export default {
	data () {
		return {
			ruleForm: {},
			purOrdNo: "", //订单号
			deliveryNo: "",//送货单号
			applySDate: "", //创建开始日期
			applyEDate: "", //创建结束日期
			companyCode: '', //客户编码
			placeholderS: '',
			placeholderE: '',
			pickerOptions: {
				disabledDate: this.disabledStartDate
			},
			pickerEndOptions: {
				disabledDate: this.disabledEndDate
			},
			billState: "", //送货单状态
			matCode: '',
			billStateOptions: [
				// {	value:1,label:'待拣配'},
				{ value: 2, label: '未审核' },
				{ value: 3, label: '已审核' }
			],
			comOptions: [],//客户下拉内容
			gridOptions: "",
			columnDefs: "",
			currentPage: 1,
			pageSize: 30,
			total: 0,
			componentShow: false,
			diaShow: true,
			getClickValue: {},
			pageLayOut: "add",
			btnShow: true,
			supplierInfo: [],
			rowSelection: "single",
			btnDis: false,
			printDis: true,
			rowDataChange: false,
			current: 0,
			textChange: 0,
			printJPDAuth: false,
			print_load: false,
			printMsg: '',
			orderShow: false,
			order: { id: '' },
			ordStatus: '',
			// 账户类型4供应商账户，1为内部用户   
			accountType: this.$global.user.userTypeId,
			supplierOptions: [],
			allSupplier: [],
			supplierCode: ''
		}
	},
	beforeMount () {
		// this.gridOptions = {
		// 	context: {
		// 		componentParent: this
		// 	},
		// 	rowSelection:"multiple",
		// 	enableColResize: true,
		//      	    localeText: localeText,
		//      	    getContextMenuItems:[],
		//      	    defaultColDef:{
		//      	    	menuTabs:[]
		//      	    },
		//      	    suppressRowClickSelection: true//单元格选中,false为选中整行
		// };

		this.columnDefs = [
			{ headerName: "送货单单号", field: "deliveryNo", width: 200, cellRenderer: buttonLink, checkboxSelection: true },
			{ headerName: "客户", field: "companyName", width: 200 },
			{ headerName: "创建日期", field: "createDate", width: 110 },
			{ headerName: "采购订单号", field: "purOrdNo", width: 120 },
			{ headerName: "计划发货日期", field: "deliveryDate", width: 140 },
			{ headerName: "实际发货日期", field: "auditDate", width: 140 },
			{				headerName: "状态", width: 100, field: "billState", cellRenderer: function (params) {
					if (params.value == "1")
						return '<span class="ag-icon">待拣配</span>';
					else if (params.value == "2")
						return '<span class="ag-icon">未审核</span>';
					else if (params.value == "3")
						return '<span class="ag-icon">已审核</span>';
				}
			}]
	},
	mounted () {
		var that = this;
		this.getBtAuth();
		this.billState = 2;
		serviceTime.getServiceTime().then((serviceTime) => {
			that.applySDate = new Date((serviceTime.getTime() - 604800000)).Format("yyyy-MM-dd");
			that.applyEDate = serviceTime.Format("yyyy-MM-dd");
			this.placeholderS = "开始日期"
			this.placeholderE = "结束日期"
			if (that.$global.user.userTypeId == "4") {
				if (!this.$global.supplierData) {
					supplierInfo.getUserInfo(this.$global.user.userName).then((supplierInfo) => {
						that.supplierInfo = supplierInfo;
						// that.search(1)
						this.getCompanyOption()
					}).catch(err => {
						that.supplierInfo = []
						that.$alert(err, {
							showClose: false,
							confirmButton: "确定",
							customClass: "alertFailure"
						});
					})
				} else {
					that.supplierInfo.push(this.$global.supplierData);
					// that.search(1)
					this.getCompanyOption()
				}
			} else {
				// that.search(1)
				this.getCompanyOption()
			}
		});
		// this.getCompanyOption()
	},
	computed: {
		...mapState({
			app: state => state.app
		})
	},
	methods: {
		...mapMutations(['setPrintData']),
		//获取按钮权限
		getBtAuth () {
			var that = this;
			this.printJPDAuth = false;
			var obj = {
				resultType: "0",
				code: 'deliveryList',
				authClientCode: constant.authCode.code,
				authTenantCode: constant.authCode.tcode
			};
			_Api.getUserAuthMenu(obj).then(function (response) {
				var data = response.data;
				if (data.code == "1") {
					if (data.total > 0) {
						for (let i in data.rows) {
							if (data.rows[i].code == "pickingPrint") {
								that.printJPDAuth = true;
							}
						}
					} else {
						that.printJPDAuth = false;
					}
				}
			}).catch((err) => {
				that.printJPDAuth = false;
				that.$alert(err.data.message, {
					showClose: false,
					confirmButton: "确定",
					customClass: "alertFailure"
				});
			})
		},
		//  限制开始日期选择范围 开始日期不大于结束日期
		disabledStartDate (time) {
			if (this.applyEDate)
				return time.getTime() > new Date(this.applyEDate).getTime();
		},
		// 限制结束日期范围 结束日期不小于开始日期
		disabledEndDate (time) {
			if (this.applySDate)
				return time.getTime() < (new Date(this.applySDate).getTime() - 3600 * 1000 * 24);
		},
		search (flag) {
			//查询
			var that = this;
			var obj = {};

			if (this.applySDate != "" && this.applyEDate != "") {
				if (this.applySDate > this.applyEDate) {
					this.$alert("提示：开始日期不能大于结束日期", {
						showClose: false,
						confirmButtonText: "确定",
						customClass: "alertPrompt"
					});
					return;
				}
			}
			obj.eqParams = {};
			obj.geParams = {};
			obj.leParams = {};
			obj.likeParams = {};

			obj.eqParams.billState = this.billState;
			if (this.$global.user.userTypeId == "4") {
				if (this.supplierInfo.length > 0) {
					obj.eqParams.supplierCode = this.supplierInfo[0].supplierCode;
				} else {
					this.$alert("提示：供应商编码不能为空", {
						showClose: false,
						confirmButtonText: "确定",
						customClass: "alertPrompt"
					});
					return
				}
				if (this.$global.isTransport) obj.eqParams.transportID = this.$global.transport.id
			} else {
				if (!this.supplierCode) {
					this.$alert("请选择供应商！", {
						showClose: false,
						confirmButtonText: "确定",
						customClass: "alertPrompt"
					});
					return
				}
				obj.eqParams.supplierCode = this.supplierCode
			}
			if (this.applySDate != "" && this.applySDate != null) {
				obj.geParams.createDate = this.applySDate;
			} else if ((this.applySDate == "" || this.applySDate == null) && this.applyEDate != "") {
				obj.geParams.createDate = this.applyEDate
			}
			if (this.applyEDate != "" && this.applyEDate != null) {
				obj.leParams.createDate = this.applyEDate
			} else if ((this.applyEDate == "" || this.applyEDate != null) && this.applySDate != "") {
				obj.leParams.createDate = this.applySDate
			}
			if (this.purOrdNo != "") {
				obj.likeParams.purOrdNo = this.purOrdNo.trim()
			}
			if (this.deliveryNo != "") {
				obj.likeParams.deliveryNo = this.deliveryNo.trim()
			}
			if (this.companyCode != "") {
				obj.eqParams.companyCode = this.companyCode
			}
			if (flag === 1)
				this.currentPage = 1;
			obj.current = this.currentPage;
			// obj.matCode = this.matCode
			obj.size = this.pageSize;
			this.$refs.agGridComponent.loading = true;
			this.btnDis = true;
			_Api.getDeliveryList(obj).then(function (response) {
				that.btnDis = false;
				that.current = 0;
				that.textChange = 0;
				var data = response.data;
				that.$refs.agGridComponent.loading = false;
				if (data.code == "1") {
					if (data.total > 0) {
						that.$refs.agGridComponent.gridOptions.api.setRowData(data.rows.splice(0));
						that.total = data.total;
						that.$refs.agGridComponent.rowDataChange = false;
					}

					else {
						that.$refs.agGridComponent.gridOptions.api.setRowData([]);
						that.total = 0;
					}
				} else {
					that.$alert(data.info, {
						showClose: false,
						confirmButton: "确定",
						customClass: "alertFailure"
					});
					that.$refs.agGridComponent.gridOptions.api.setRowData([]);
					that.total = 0;
					that.btnDis = false;
				}
			}).catch((err) => {
				console.log(err)
				that.$alert(err.data.message, {
					showClose: false,
					confirmButton: "确定",
					customClass: "alertFailure"
				});
				that.btnDis = false;
				that.$refs.agGridComponent.gridOptions.api.setRowData([]);
				that.total = 0;
				that.$refs.agGridComponent.loading = false;
				that.current = 0;
				that.textChange = 0;
			})
		},
		del () {
			//删除
			var rows = this.$refs.agGridComponent.gridOptions.api.getSelectedRows();
			var that = this;
			const h = this.$createElement;
			if (rows.length <= 0) {
				this.$alert("提示：请选择需要删除的数据", {
					showClose: false,
					confirmButtonText: "确定",
					customClass: "alertPrompt"
				});
				return;
			}
			this.$msgbox({
				title: '系统提醒',
				message: h('p', null, [
					h('span', null, '是否确认删除该数据？'),
					h('strong', { style: 'color: red' }, '(注意：若删除的送货单已送货将会影响后续交货入库，请谨慎操作！)')
				]),
				showCancelButton: true,
				confirmButtonText: '确定',
				cancelButtonText: '取消',
			})
				// this.$confirm("是否确认删除该数据？(注意：若删除的送货单未完结将会影响后续交货入库等相关操作)", "消息提示", {
				//   confirmButtonText: "确定",
				//   cancelButtonText: "取消",
				//   center:true,
				//   distinguishCancelAndClose: true
				// })
				.then(() => {
					let id = '';
					for (let i = 0; i < rows.length; i++) {
						id += rows[i].id + ',';
					}
					id = id.substr(0, id.length - 1);
					let obj = {
						id: id,
						delFlag: 1,
						modifyer: this.$global.user.loginName,
						modifyerId: this.$global.user.id
					}
					_Api.deleteDeliveryList(obj).then(function (response) {
						let data = response.data;
						if (data.code == "1") {
							that.$message({
								message: "操作成功",
								type: "success"
							});
						} else {
							that.$alert(data.info, {
								showClose: false,
								confirmButton: "确定",
								customClass: "alertFailure"
							});
						}
						that.search();
					}).catch((err) => {
						that.$alert(err.data.message, {
							showClose: false,
							confirmButton: "确定",
							customClass: "alertFailure"
						});
					})
				}).catch(() => { })
		},
		print1 () {
			//拣配单打印
			var rows = this.$refs.agGridComponent.gridOptions.api.getSelectedRows();
			if (rows.length <= 0) {
				this.$alert("提示：请选择需要打印的数据", {
					showClose: false,
					confirmButtonText: "确定",
					customClass: "alertPrompt"
				});
				return;
			}
			var that = this
			waterfall([
				function getServiceTime (callback) {
					serviceTime.getServiceTime().then((serviceTime) => {
						var printTime = serviceTime.Format("yyyy-MM-dd HH:mm:ss");
						callback(null, printTime);
					});
				},
				function getDeliverybillDetail (servicetTime, callback) {
					_Api.getDeliverybillDetail({ deliveryBillId: rows[0].id }).then(function (response) {
						var data = response.data;
						if (data.code == "1") {
							if (data.total > 0) {
								var tempArr = [];
								var detailRows = data.rows.tblDeliverymxs.splice(0);
								for (let i in detailRows) {
									var obj = {};
									obj.tabRemark = rows[0].remark;
									obj.carNum = data.rows.carNum;
									obj.address = rows[0].address;
									obj.deliveryDate = rows[0].deliveryDate;
									obj.printDate = servicetTime;
									obj.createDate = rows[0].createDate;
									obj.purOrdNo = rows[0].purOrdNo;
									obj.deliveryNo = rows[0].deliveryNo;
									obj.creator = rows[0].creator; // this.$global.user.employeeName;
									obj.supplierName = rows[0].supplierName;
									obj.companyName = rows[0].companyName;
									obj.matCode = detailRows[i].matCode;
									obj.matName = detailRows[i].matName;
									obj.priceAmount = detailRows[i].priceAmount;
									obj.priceUnit = detailRows[i].priceUnit;
									//jjc
									obj.auxAmount = detailRows[i].priceAmount + " " + detailRows[i].priceUnit;
									// if(detailRows[i].planAmount > 0)
									// {
									// 	if(detailRows[i].denominator == null || detailRows[i].denominator <= 0)
									// 		detailRows[i].denominator = 1;
									// 	obj.planAuxAmount = detailRows[i].planAmount * detailRows[i].numerator / detailRows[i].denominator +" " + detailRows[i].priceUnit;
									// }											
									obj.unitCode = detailRows[i].unitCode;
									obj.actualAmount = detailRows[i].actualAmount;
									obj.remark = rows[0].remark; //送货单备注
									obj.mxremark = detailRows[i].remark; //明细备注
									obj.planAmount = detailRows[i].actualAmount;
									tempArr.push(obj)
								}
								callback(null, tempArr);
							}
						}
					})
				},
				function print (tempArr, callback) {
					if (constant.printType == 'local') {
						ipcRenderer.send("IPCR_M_PRINTLOCAL", {
							type: "delivery",
							rows: tempArr,
							optype: 'pr',
							isdefaultp: 1//控制是否直接打印,0为选择打印、1为直接打印
						});
					} else {
						fileStream.getFileInfo("delivery_pc", tempArr).then((data) => {
							ipcRenderer.send("IPCR_M_PRINT", {
								type: "delivery_pc",
								rows: tempArr,
								groupName: data.groupName,
								optype: "pr",
								url: data.url,
								isdefaultp: 1//控制是否直接打印,0为选择打印、1为直接打印
							});
						}).catch((err) => {
							that.$alert(err, {
								showClose: false,
								confirmButton: "确定",
								customClass: "alertFailure"
							});
						})
					}
				}
			])
		},
		print2 () {
			//送货单打印
			var rows = this.$refs.agGridComponent.gridOptions.api.getSelectedRows();
			if (rows.length <= 0) {
				this.$alert("提示：请选择需要打印的数据", {
					showClose: false,
					confirmButtonText: "确定",
					customClass: "alertPrompt"
				});
				return;
			}
			var that = this
			waterfall([
				function getServerTime (callback) {
					serviceTime.getServiceTime().then((serviceTime) => {
						var printTime = serviceTime.Format("yyyy-MM-dd HH:mm:ss");
						callback(null, printTime);
					});
				},
				function getDeliverybillDetail (serviceTime, callback) {
					_Api.getDeliverybillDetail({ deliveryBillId: rows[0].id }).then(function (response) {
						var data = response.data;
						if (data.code == "1") {
							if (data.total > 0) {
								var tempArr = [];
								var detailRows = data.rows.tblDeliverymxs.splice(0);
								for (let i in detailRows) {
									var obj = {};
									obj.tabRemark = rows[0].remark;
									obj.carNum = data.rows.carNum;
									obj.address = rows[0].address;
									obj.deliveryDate = rows[0].deliveryDate;
									obj.printDate = serviceTime;
									obj.createDate = rows[0].createDate;
									obj.purOrdNo = rows[0].purOrdNo;
									obj.deliveryNo = rows[0].deliveryNo;
									obj.creator = rows[0].creator; //this.$global.user.employeeName;
									obj.supplierName = rows[0].supplierName;
									obj.companyName = rows[0].companyName;
									obj.matCode = detailRows[i].matCode;
									obj.matName = detailRows[i].matName;
									obj.unitCode = detailRows[i].unitCode;
									obj.actualAmount = detailRows[i].actualAmount;
									obj.remark = rows[0].remark; //送货单备注
									obj.mxremark = detailRows[i].remark; //明细备注
									//jjc
									obj.auxAmount = detailRows[i].priceAmount + " " + detailRows[i].priceUnit;
									// if(detailRows[i].actualAmount > 0)
									// {
									// 	if(detailRows[i].denominator == null || detailRows[i].denominator <= 0)
									// 		detailRows[i].denominator = 1;
									// 	obj.auxAmount = detailRows[i].actualAmount * detailRows[i].numerator / detailRows[i].denominator +" " + detailRows[i].priceUnit;
									// }	

									obj.priceUnit = detailRows[i].priceUnit;
									tempArr.push(obj)
								}
								callback(null, tempArr);
							}
						}
					})
				},
				function print (tempArr, callback) {
					if (constant.printType == 'local') {
						ipcRenderer.send("IPCR_M_PRINTLOCAL", {
							type: "sendDelivery",
							rows: tempArr,
							// systemType: "srm",
							optype: 'pr'
						});
					} else {
						fileStream.getFileInfo("sendDelivery_pc", tempArr).then((data) => {
							ipcRenderer.send("IPCR_M_PRINT", {
								type: "sendDelivery_pc",
								rows: tempArr,
								groupName: data.groupName,
								optype: "pr",
								url: data.url,
								isdefaultp: 1//控制是否直接打印,0为选择打印、1为直接打印
							});
						}).catch((err) => {
							that.$alert(err, {
								showClose: false,
								confirmButton: "确定",
								customClass: "alertFailure"
							});
						})
					}
				}
			])
		},
		// 客户端送货单or拣配单打印
		printPc (type) {
			let rows = this.$refs.agGridComponent.gridOptions.api.getSelectedRows()
			if (rows.length <= 0) {
				this.$alert("提示：请选择需要打印的数据", {
					showClose: false,
					confirmButtonText: "确定",
					customClass: "alertPrompt"
				})
				return
			}
			const ENCRYPT_KEY = 'lesso2128token11'
			waterfall([
				(callback) => {
					this.$http.getPrintToken().then(({ data }) => {
						let token = aes.encrypt(data, ENCRYPT_KEY);
						callback(null, token);
					}).catch(err => {
						this.$alert(err.data.message, {
							showClose: false,
							confirmButton: "确定",
							customClass: "alertFailure"
						});
					})
				},
				(token, callback) => {
					this.$http.getDeliveryPrintData({ id: rows[0].id, token: token, supplierCode: rows[0].supplierCode }).then(({ data }) => {
						let printData = data.rows
						callback(null, printData)
					}).catch(err => {
						this.$alert(err.data.message, {
							showClose: false,
							confirmButton: "确定",
							customClass: "alertFailure"
						});
					})
				},
				(printData, callback) => {
					if (constant.printType == 'local') {
						ipcRenderer.send("IPCR_M_PRINTLOCAL", {
							type: type,
							rows: printData,
							optype: 'pr',
							isdefaultp: 1//控制是否直接打印,0为选择打印、1为直接打印
						});
					} else {
						fileStream.getFileInfo(type, printData).then((data) => {
							ipcRenderer.send("IPCR_M_PRINT", {
								type: type,
								rows: printData,
								groupName: data.groupName,
								optype: "pr",
								url: data.url,
								isdefaultp: 1//控制是否直接打印,0为选择打印、1为直接打印
							})
						}).catch((err) => {
							this.$alert(err, {
								showClose: false,
								confirmButton: "确定",
								customClass: "alertFailure"
							});
						})
					}
				}
			])
		},
		// 打印送货单或拣配单
		printTemp (type) {
			if (constant.userAgent == 'web') {
				var rows = this.$refs.agGridComponent.gridOptions.api.getSelectedRows();
				if (rows.length <= 0) {
					this.$alert("提示：请选择需要打印的数据", {
						showClose: false,
						confirmButtonText: "确定",
						customClass: "alertPrompt"
					});
					return;
				}
				fileStream.getFileInfo(type).then((data) => {
					startPrint({
						basicUrl: ENV['srm'], //权限接口地址
						reportUrl: `${ENV['srm']}download2?viewPath=${data.url}&groupName=${data.groupName}`, //打印模板地址
						dataUrl: 'tblDeliverybill/deliverybillInfo', //数据接口地址
						params: {
							'token': '',
							'id': rows[0].id,
							'supplierCode': rows[0].supplierCode
						}, //参数对象
						printType: 'preview'     // 打印方式print直接打印，preview先预览
					})
				}).catch((err) => {
					that.$alert(err, {
						showClose: false,
						confirmButton: "确定",
						customClass: "alertFailure"
					});
				})
			} else {
				if (type == 'delivery') {
					this.printPc('delivery_pc')
				} else (
					this.printPc('sendDelivery_pc')
				)
			}
		},
		// 选择送货单打印方式回调
		handleCommand (command) {
			switch (command) {
				case "1":
					this.printTemp('sendDelivery')
					break;
				case "2":
					this.printTemp('sendDelivery')
					break;
				case "3":
					this.printTemp('delivery')
					break;
				case "4":
					this.printTemp('delivery')
					break;
			}
		},
		handleSizeChange (params) {
			this.currentPage = 1;
			this.pageSize = params;
			this.search();
		},
		handleCurrentChange (params) {
			// this.currentPage = params;
			if (this.textChange === 1 || this.current === 1)
				this.currentPage = 1;
			else
				this.currentPage = params;
			this.search();
		},
		handlePrevClick (params) {
			if (this.textChange === 1 || this.current === 1)
				this.currentPage = 1;
			else
				this.currentPage = params;
		},
		handleNextClick (params) {
			if (this.textChange === 1 || this.current === 1)
				this.currentPage = 1;
			else
				this.currentPage = params;
		},
		setClickValue (value) {
			// this.$emit('getClickValue',value);
			this.getClickValue = value.data;
			this.pageLayOut = "edit";
			this.diaShow = false;
			this.componentShow = true;
		},
		cancelComponents (msg) {
			if (msg) {
				var that = this;
				this.componentShow = false;
				this.orderShow = false;
				this.diaShow = true;
				this.$nextTick(_ => {
					that.search();
				})
			}
		},
		viewOrder (orderObj) {
			this.diaShow = false;
			this.componentShow = false;
			this.orderShow = true
			this.order.id = orderObj.orderId
			this.ordStatus = orderObj.ordStatus
		},
		billStateChange (params) {
			this.search();
			if (params > 2)
				this.btnShow = false;
			else
				this.btnShow = true;
			if (params === 1 || params === 2)
				this.printDis = true;
			else
				this.printDis = false;
		},
		// 根据账户类型获取公司下拉列表
		getCompanyOption () {
			authInfo
				.getAuthInfo()
				.then(data => {
					this.comOptions = data
					this.companyCode = this.comOptions[0].companyCode
					if (this.$global.user.userTypeId == "1") {
						this.getAuthSuppliers(this.comOptions[0].companyCode)
					} else {
						this.search(1)
					}
				})
				.catch(err => {
					this.$alert(err, {
						showClose: false,
						confirmButton: "确定",
						customClass: "alertFailure"
					});
				});
		},
		// 获取当前公司所有供应商
		getAuthSuppliers (companyCode) {
			this.formLoading = true
			this.supplierCode = ''
			this.$http.getAuthSupplierByCompanyCode({ name: companyCode }).then(({ data }) => {
				this.formLoading = false
				if (data.code == 1) {
					this.supplierOptions = data.rows
					this.allSupplier = data.rows
				} else {
					Msg.showErrorMsg(data.info)
				}
			}).catch(err => {
				this.formLoading = false
				Msg.showErrorMsg(err.data.message)
			})
		},
		// 筛选供应商
		filterSupplier (value) {
			if (value != '') {
				this.supplierOptions = this.allSupplier.filter(item => item.supplierCode.indexOf(value) > -1 || item.supplierName.indexOf(value) > -1)
			} else {
				this.supplierOptions = this.allSupplier
			}
		},
		// 供应商下拉框获取焦点
		focusMethod () {
			if (!this.companyCode) {
				Msg.showPopMsg('请先选择公司!')
				this.$refs.content.focus();
			}
		},
		// 供应商选择框下拉
		supplierChange (val) {
			for (let i = 0; i < this.supplierOptions.length; i++) {
				if (val == this.supplierOptions[i].supplierCode) {
					this.supplierName = this.supplierOptions[i].supplierName
					this.supplierInfo.push({
						supplierName: this.supplierOptions[i].supplierName,
						supplierCode: this.supplierOptions[i].supplierCode,
						id: this.supplierOptions[i].id
					})
					return
				}
			}
		},
		// 选择公司下拉
		companyChange (val) {
			if (this.accountType == 1) {
				this.getAuthSuppliers(val)
			}
		}
	},
	components: {
		agGridComponents,
		deliveryComponents,
		purOrderDetailsComponents
	},
	watch: {
		supplierInfo (value) {
		},
		purOrdNo (val) {
			//采购单号
			if (val)
				this.textChange = 1;
			else
				this.textChange = 0;
		},
		applySDate () {
			this.current = 1;
		},
		applyEDate () {
			this.current = 1;
		},
		billState () {
			this.current = 1;
		}
	},
	created: function () {

	}
}
</script>